package org.gdpu.service.impl;

import org.gdpu.base.DaoSupport;
import org.gdpu.model.BloodSum;
import org.gdpu.model.Office;
import org.gdpu.service.BloodSumService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: willson
 * Date: 13-11-7
 * Time: 上午9:14
 * To change this template use File | Settings | File Templates.
 */

@Service
@Transactional
public class BloodSumServiceImpl extends DaoSupport<BloodSum> implements BloodSumService {

    @Override
    public boolean bloodVolume(String bloodType, double bloodVolume,boolean flag) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("bloodType", bloodType);
        BloodSum  blood = (BloodSum) this.findSpecialObject(BloodSum.class, params);
        if(flag)
            blood.setSum(bloodVolume+blood.getSum());
        else
            blood.setSum(blood.getSum()-bloodVolume);
        try{
            this.update(blood);
            return true;
        }catch (Exception e){
            return false;
        }
    }
}
